Ext.define('PJ.view.assessmentresultvist.List', {
    extend: 'AM.default.DefaultList',
    requires: ['AM.default.DefaultSearchForm', 
               'AM.default.DateTime', 
               'AM.default.DefaultDateField',
               'PJ.view.assessmentresultvist.UsersList'//已评估人员列表
               ],
    /* selModel: {
         selType: '',
         // 设置为只能通过复选框选中行
         checkOnly: true 
     },*/
    initComponent: function(){
    	var me = this;
        me.columns = [{
            header: '培训班编号',
            dataIndex: 'classCount.classNum',
            width: 90,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '培训班问卷名称',
            dataIndex: 'classCount.className',
            flex: 1,
            minWidth: 120,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '主办单位',
            dataIndex: 'classCount.sponsorName',
            width: 120,
			renderer: function(value, metaData, record){
				metaData.tdAttr = 'data-qtip="' + value + '"';
				return value;
			}
        }, {
            header: '开班时间',
            dataIndex: 'classCount.beginDate',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '结业时间',
            dataIndex: 'classCount.endDate',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '评估开始时间',
            dataIndex: 'classCount.assessStartTime',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }, {
            header: '评估结束时间',
            dataIndex: 'classCount.assessEndTime',
            width: 90,
            renderer: function(value, metaData, record){
                return value;
            }
        }/*, {
            header: '已报人数/计划人数',
            dataIndex: 'planCount',
            width: 130,
            sortable: false,
            renderer: function(value, metaData, record){
            	var reportedNum = record.get('reportedNum');
            	return reportedNum + "/" + value;
            }
        }*/, {
            header: '已评估人数',
            dataIndex: 'classCount.answerUser',
            width: 80,
            renderer: function(value, meta, record){
            	var m=record.get("questionnaireMethod");
            	if(m==1&&value!=0)
            		meta.style = "overflow: hidden;text-overflow: ellipsis;cursor: pointer;color: blue;";
                meta.tdAttr = 'data-qtip="' + value + '" paperID=' + record.get("classId") + ' questionnaireId="' + record.get("questionnaireId") + '" questionnaireMethod="' + record.get("questionnaireMethod") + '"';
                return value;
            },
            listeners: {
                click: function(g, clm){
                	var m=clm.getAttribute("questionnaireMethod");
                	var count=clm.getAttribute('data-qtip');
                	if(m==1&&count!=0){
                		Ext.create('AM.default.DefaultWindowView', {
                			title: "查看人员信息",
                			grid: g,
                			paperId: clm.getAttribute("paperID"),
                			answerUserStatus: 1,
                			searchQuestionnaireId: clm.getAttribute("questionnaireId"),
                			width: 615,
                			height: 350,
                			items: [{
                				xtype: 'assessmentUsersList'
                			}]
                		}).show();
                	}
                }
            }
        }, {
            header: '未评估人数',
            dataIndex: 'classCount.noAnswerUser',
            width: 80,
            renderer: function(value, meta, record){
            	var m=record.get("questionnaireMethod");
            	if(m==1&&value!=0)
            		meta.style = "overflow: hidden;text-overflow: ellipsis;cursor: pointer;color: blue;";
            	meta.tdAttr = 'data-qtip="' + value + '" paperID=' + record.get("classId") + ' questionnaireId="' + record.get("questionnaireId") + '" questionnaireMethod="' + record.get("questionnaireMethod") + '"';
                return value;
            },
            listeners: {
                click: function(g, clm){
                	var m=clm.getAttribute("questionnaireMethod");
                	var count=clm.getAttribute('data-qtip');
                	if(m==1&&count!=0){
	                    Ext.create('AM.default.DefaultWindowView', {
	                        title: "查看人员信息",
	                        grid: g,
	                        paperId: clm.getAttribute("paperID"),
	                        answerUserStatus: 2,
	                        searchQuestionnaireId: clm.getAttribute("questionnaireId"),
	                        width: 615,
	                        height: 350,
	                        items: [{
	                        	xtype: 'assessmentUsersList'
	                        }]
	                    }).show();
	            	}
                }
            }
        }/*,{
            header: '参评率（%）',
            dataIndex: 'nswerPerc',
            width: 90,
            sortable: false,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        }*/];
        me.store = Ext.create('PJ.'+ prototype +'.assessmentresultvist.List', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        me.callParent(arguments);
    },
    //导出
    onExportClick: function(){
    	var me = this;
    	var records = me.getSelectionModel().getSelection();
        var store = me.getStore();
        var params=store.proxy.extraParams;
        var href=me.store.classDetailsUrl + '?page=-1&searchClassId=' + records[0].get("classId") + '&questionnaireId=' + records[0].get("questionnaireId");
    	if(records.length > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '只允许操作一条数据！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
    		return;
    	}
        for(var param in params){
        	if(params[param] === undefined){
        		href+="&"+param+"=";
        	}else{
        		href+="&"+param+"="+params[param];
        	}
        }
        href = encodeURI(href);
        var atag = Ext.get("exportResume");
        atag.set({
            "href": href
        });
        atag.dom.click();
    },
    //导出
    onExportCourseClick: function(exportUrl){
    	var me = this;
    	var records = me.getSelectionModel().getSelection();
        var store = me.getStore();
        var params=store.proxy.extraParams;
        var href=me.store.exportCourseUrl;
		if(records != null && records.length > 0){
			href=me.store.exportCourseUrl + '?searchClassIds=' + records[0].get('classId');
			for(var i = 1;i<records.length;i++){
				href += '&searchClassIds=' + records[i].get('classId');
			}
		}
        for(var param in params){
        	if(params[param] === undefined){
        		href+="&"+param+"=";
        	}else{
        		href+="&"+param+"="+params[param];
        	}
        }
        href = encodeURI(href);
        var atag = Ext.get("exportResume");
        atag.set({
            "href": href
        });
        atag.dom.click();
    },
    listeners: {
    	selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "Export").setDisabled(selected.length === 0);
        },
    	viewready: function(){
    		var me = this;
	    	//导出按钮集合
	    	var exportMenu = Ext.create('Ext.menu.Menu', {
	            items: [{
	                text: '培训班汇总',
	        		iconCls: 'classDetailsIco',
	                listeners: {
	                	click: function(btn){
	                    	var records = me.getSelectionModel().getSelection();
	                        var store = me.getStore();
	                        var params=store.proxy.extraParams;
	                        var classIds= new Array();
	    					Ext.Array.each(records,function(name,index){
	    						classIds.push(name.get('classId'));
	    					});
	    					var questionnaireIds=new Array();
	    					Ext.Array.each(records,function(name,index){
	    						questionnaireIds.push(name.get('questionnaireId'));
	    					});
	                        var href=me.store.classOriginalUrl;
	                        for(var param in params){
	                        	if(params[param] === undefined){
	                        		href+="&"+param+"=";
	                        	}else{
	                        		href+="&"+param+"="+params[param];
	                        	}
	                        }
	                        href = encodeURI(href);
	                        var atag = Ext.get("exportResume");
	                        atag.set({
	                            "href": href
	                        });
	                        atag.dom.click();
	                	}
	                }
	            }, {
	                text: '汇总',
	        		iconCls: 'classDetailsIco',
	                listeners: {
	                	click: function(btn){
	                    	var records = me.getSelectionModel().getSelection();
	                        var store = me.getStore();
	                        var params=store.proxy.extraParams;
	                    	if(records.length > 1||records.length<1){
	                            Ext.Msg.show({
	                                title: '提示',
	                                msg: '只允许操作并至少操作一条数据！',
	                                icon: Ext.Msg.WARNING,
	                                buttons: Ext.Msg.OK
	                            });
	                    		return;
	                    	}
//	                    	if(records[0].get("questionnaireMethod")==2){
//	                    		Ext.Msg.show({
//	                    			title: '提示',
//	                    			msg: '只能导出实名评估汇总表！',
//	                    			icon: Ext.Msg.WARNING,
//	                    			buttons: Ext.Msg.OK
//	                    		});
//	                    		return;
//	                    	}
	                    	var href=me.store.classScoreUrl + '?page=-1&searchClassId=' + records[0].get("classId") + '&searchQuestionnaireId=' + records[0].get("questionnaireId");
	                        for(var param in params){
	                        	if(params[param] === undefined){
	                        		href+="&"+param+"=";
	                        	}else{
	                        		href+="&"+param+"="+params[param];
	                        	}
	                        }
	                        href = encodeURI(href);
	                        var atag = Ext.get("exportResume");
	                        atag.set({
	                            "href": href
	                        });
	                        atag.dom.click();
	                    	//me.onExportClick();
	                	}
	                }
	            }, {
	                text: '原始汇总',
	        		iconCls: 'scoreIco',
	                listeners: {
	                	click: function(btn){
	                		var records = me.getSelectionModel().getSelection();
	                        var store = me.getStore();
	                        var params=store.proxy.extraParams;
	                        if(records.length > 1||records.length<1){
	                            Ext.Msg.show({
	                                title: '提示',
	                                msg: '只允许操作并至少操作一条数据！',
	                                icon: Ext.Msg.WARNING,
	                                buttons: Ext.Msg.OK
	                            });
	                    		return;
	                    	}
//	                        if(records[0].get("questionnaireMethod")==2){
//	                    		Ext.Msg.show({
//	                    			title: '提示',
//	                    			msg: '只能导出实名评估原始汇总表！',
//	                    			icon: Ext.Msg.WARNING,
//	                    			buttons: Ext.Msg.OK
//	                    		});
//	                    		return;
//	                    	}
	                        var href=me.store.classDetailsUrl + '?page=-1&classId=' + records[0].get("classId") + '&questionnaireId=' + records[0].get("questionnaireId") + '&assessExport=1';
	                        for(var param in params){
	                        	if(params[param] === undefined){
	                        		href+="&"+param+"=";
	                        	}else{
	                        		href+="&"+param+"="+params[param];
	                        	}
	                        }
	                        href = encodeURI(href);
	                        var atag = Ext.get("exportResume");
	                        atag.set({
	                            "href": href
	                        });
	                        atag.dom.click();
	                    	//me.onExportClick();
	                	}
	                }
	            }, {
	                text: '学员评估详情',
	        		iconCls: 'reportCardIco',
	                listeners: {
	                	click: function(btn){
	                		var records = me.getSelectionModel().getSelection();
	                        var store = me.getStore();
	                        var params=store.proxy.extraParams;
	                        if(records.length > 1||records.length<1){
	                            Ext.Msg.show({
	                                title: '提示',
	                                msg: '只允许操作并至少操作一条数据！',
	                                icon: Ext.Msg.WARNING,
	                                buttons: Ext.Msg.OK
	                            });
	                    		return;
	                    	}
//	                        if(records[0].get("questionnaireMethod")==2){
//	                    		Ext.Msg.show({
//	                    			title: '提示',
//	                    			msg: '只能导出实名学员评估详情表！',
//	                    			icon: Ext.Msg.WARNING,
//	                    			buttons: Ext.Msg.OK
//	                    		});
//	                    		return;
//	                    	}
	                        var href=me.store.classDetailsUrl + '?page=-1&classId=' + records[0].get("classId") + '&questionnaireId=' + records[0].get("questionnaireId") + '&assessExport=2';
	                        for(var param in params){
	                        	if(params[param] === undefined){
	                        		href+="&"+param+"=";
	                        	}else{
	                        		href+="&"+param+"="+params[param];
	                        	}
	                        }
	                        href = encodeURI(href);
	                        var atag = Ext.get("exportResume");
	                        atag.set({
	                            "href": href
	                        });
	                        atag.dom.click();
	                    	//me.onExportClick();
	                	}
	                }
	            }]
	        });
    		me.addDocked([{
    			dock: 'top',
    			xtype: "searchform",
    			columnCount: 3,
    			fieldDefaults: {
    				labelAlign: 'right',
    				labelWidth: 70
    			},
    			items: [{
    				xtype: "textfield",
    				fieldLabel: '培训班编号',
    				name: "searchClassNum",
    				maxLength: "50",
    				emptyText: "请输入培训班编号"
    			}, {
    				xtype: "textfield",
    				fieldLabel: '培训班问卷名称',
    				name: "searchClassName",
    				maxLength: "20",
    				emptyText: "请输入培训班问卷名称",
    				labelWidth: 90
    			}, {
    				xtype: "textfield",
    				fieldLabel: '主办单位',
    				name: "searchSponsorName",
    				emptyText: "请输入主办单位"
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '开班时间',
    				name: 'searchBeginDate',
    				id: 'searchBeginClassSD',
    				vtype: 'startLessEndDate',
    				startLessEndDate: {
    					targetCmpId: 'searchBeginClassSD',
    					isStart: true
    				},
    				emptyText: "请输入开班时间"
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '结业时间',
    				name: 'searchEndDate',
    				id: 'searchGraduationClassED',
    				vtype: 'startLessEndDate',
    				vtypeText: '结业时间不能早于开班时间！',
    				startLessEndDate: {
    					targetCmpId: 'searchGraduationClassED',
    					isStart: false
    				},
    				emptyText: "请输入结业时间",
    				labelWidth: 90
    			}],
    			grid: this
    		}, {
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '导出',
                	xtype: 'button',
                    cls: 'floater',
                    textAlign: 'right',
                    arrowAlign: 'right',
                    itemId: this.oldId + 'Export',
//                    disabled: true,
                    enableToggle: true,
                    iconAlign: 'left',
                    iconCls: 'deriveIco',
                    pressedCls: 'x-btn-focus',
                    menuActiveCls: 'x-btn-menu-active',
                    menu: exportMenu/*,
                    handler: this.onExportClick*/
                },'-',{
                	text: '课程评估结果导出',
                    iconCls: 'reportCardIco',
                    itemId: this.oldId + "ExportCourse",
                    disabled: false,
                    scope: this,
                    handler: this.onExportCourseClick
                }, "->", this.countSelectPanel]
            }]);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {};
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    	}
    }
});
